import random
ans = random.randint(int(input("Left side of range:")),int(input("Right side of range:")))   #生成随机数并自定义随机数生成范围
bat = int(input("Input the times you want to try:"))   #输入要猜的次数
x = int(input("Please guess a number:"))   #第一次猜
cnt = int(1)   #初始化计数为1
for i in range(1,bat):   #在规定猜的次数内循环
    if x == ans:   #猜中了
        print("You Win! The random number is ",ans)
        print("\n")
        print("You have tried",cnt)
        break   #跳出循环
    if x<ans:   #猜小了
        print("Too Small")
        x = int(input("Please try again:"))
        print("Residue time: ",int(bat-i-1))   #计算剩余猜测次数，下同
        cnt = cnt+1
        continue   #继续下一轮循环，下同
    elif x>ans:   #猜大了
        print("Too large")
        x = int(input("Please try again:"))
        print("Residue time: ",int(bat-i-1))
        cnt = cnt+1
        continue
if cnt == bat:   #循环结束后则必有该等式，输掉的情况
    print("You lose!")
    print("The random number is: ",ans)